import random

from faker import Faker

FAKE = Faker("zh_CN")
def generate_id_card():
    """
    生成一个模拟的身份证号码

    返回值:
    str: 模拟的身份证号码
    """
    # 地址码（随机从一些常见地址码中选取，实际应用中应根据真实地区对应）
    address_codes = ["110000", "120000", "310000", "440000", "510000"]
    address_code = random.choice(address_codes)

    # 出生日期码（随机生成一个在合理范围内的出生日期）
    birth_year = random.randint(2000, 2024)
    birth_month = random.randint(1, 12)
    if birth_month in [1, 3, 5, 7, 8, 10, 12]:
        max_days = 31
    elif birth_month in [4, 6, 9, 11]:
        max_days = 30
    else:
        max_days = 28 if birth_year % 4!= 0 or (birth_year % 100 == 0 and birth_year % 400!= 0) else 29
    birth_day = random.randint(1, max_days)
    birth_date_code = f"{birth_year}{birth_month:02d}{birth_day:02d}"

    # 顺序码（随机三位数字，最后一位根据性别决定，奇数为男性，偶数为女性，这里随机）
    sequence_code = f"{random.randint(0, 999):03d}"

    # 校验码计算（按照身份证校验码的计算规则）
    factors = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]
    all_digits = [int(digit) for digit in f"{address_code}{birth_date_code}{sequence_code}"]
    total = sum([a * b for a, b in zip(factors, all_digits)])
    remainder = total % 11
    verification_code_dict = {0: '1', 1: '0', 2: 'X', 3: '9', 4: '8', 5: '7', 6: '6', 7: '5', 8: '4', 9: '3', 10: '2'}
    verification_code = verification_code_dict[remainder]

    id_card_number = f"{address_code}{birth_date_code}{sequence_code}{verification_code}"

    return id_card_number
import hashlib


def id_card_md5(id_card_number):
    """
      对身份证号码进行MD5加密

      参数:
      id_card_number (str): 要加密的身份证号码

      返回值:
      str: 加密后的MD5值
      """
    md5 = hashlib.md5()
    md5.update(id_card_number.encode('utf-8'))
    return md5.hexdigest()
def phone_number_md5():
    md5 = hashlib.md5()
    md5.update(FAKE.phone_number().encode('utf-8'))
    return md5.hexdigest()
if __name__ == '__main__':
    print(generate_id_card())
    print(id_card_md5(generate_id_card()))
    print(phone_number_md5())